
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>帮你推荐</title>
  <link rel="stylesheet" href="__PUBLIC__/mobile/css/public.css">
  <link rel="stylesheet" href="__PUBLIC__/mobile/css/login.css">

  <link href="__PUBLIC__/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
  <script type="text/javascript" src="__PUBLIC__/layui.js"></script>

  <script src="__PUBLIC__/mobile/js/jquery-1.8.3.min.js" type="text/javascript"></script>
  <script src="__PUBLIC__/mobile/js/wxd.js" type="text/javascript"></script>

    <style type="text/css">
    .sendcode{
position: absolute;
    width: 100px !important;
    right: 0;
    top: 0;
    text-align: center;
    padding: 0 !important;
    background-color: #094;
    color: #fff;
    border-radius: 5px !important;
    cursor:pointer;
    }
  </style>
</head>
<body>
  <header class="nav">
      <a class="nav-return" href="{:U('mobile/info/ls_home',array('newcity'=>$city))}"></a>
      <h1 class="nav-title">需求信息</h1>
      <span class="nav-right">
          <a class="nav-btn-reg" href="{:U('mobile/info/ls_home',array('newcity'=>$city))}">返回</a>
      </span>
  </header>
  
  <section class="main">
      <div class="logo">
          <img width="230" height="64" class="logo" src="__PUBLIC__/mobile/images/logo.png">
      </div>
      <form class="form layui-form" method="post">
          <div class="input-wrap">
              <span style=" position: absolute;padding-top: 7px;">学生姓名：</span>
              <input type="text" name="name" lay-verify="name" placeholder="请输入学生姓名" style="padding-left: 80px;">
              <i class="i-close"></i>
          </div>
          <div class="input-wrap">年级类别：
              <select name="grade" id="" lay-verify="grade">
                      <option value="">选择年级</option>
                  <?php foreach ($grades as $v) { ?>
                      <option value="{$v['grade_name']}">{$v['grade_name']}</option>
                  <?php } ?>
              </select>
              <i class="i-close"></i>
          </div>
          <div class="input-wrap">辅导科目：
              <select name="kemu" id="" lay-verify="kemu">
                      <option value="">选择科目</option>
                  <?php foreach ($kemus as $v) { ?>
                      <option value="{$v['name']}">{$v['name']}</option>
                  <?php } ?>
              </select>
              <i class="i-close"></i>
          </div>
          <div class="input-wrap">
              <span style=" position: absolute;padding-top: 7px;">上课地址：</span>
              <input type="text" name="addr" placeholder="请输入大致位置" style="padding-left: 80px;">
              <i class="i-close"></i>
          </div>
          <div class="input-wrap">
              <span style=" position: absolute;padding-top: 7px;">手机号码：</span>
              <input type="text" lay-verify="phone" name="phone" placeholder="请输入手机号码" style="padding-left: 80px;">
              <i class="i-close"></i>
          </div>
          <div class="input-wrap p-code">
              <i class="i-code"></i>
              <input class="code" name="send_to" lay-verify="send_to" placeholder="请输入短信码" type="text">
              <i class="i-close"></i>
              <input class="sendcode" id="getcodes" value="获取短信码" type="button" onclick="get_mobile_valid()">
          </div>
          <div class="input-wrap">
              <span style=" position: absolute;padding-top: 7px;">需求备注：</span>
              <input type="text" name="beizhu" placeholder="请输入需求备注" style="padding-left: 80px;">
              <i class="i-close"></i>
          </div>
          <input type="hidden" name="city" value="{$city}">
          <button class="btn-submit" style="margin-top: 20px;" lay-submit lay-filter="*">提&nbsp;&nbsp;交</button>
      </form>
  </section>
<script type="text/javascript">
    layui.use(['form','layer'], function(){
      var layer = layui.layer
      ,form = layui.form();
      //layer.msg('Hello World');

    //自定义验证规则
    form.verify({
      name: function(value){
        if(value.length < 1){
          return '学生姓名不能为空';
        }
      }
      ,grade: function(value){
        if(value.length < 1){
          return '年级类别不能为空';
        }
      }
      ,kemu: function(value){
        if(value.length < 1){
          return '辅导科目不能为空';
        }
      }
      ,phone: function(value){
        if(value.length < 1){
          return '手机号码不能为空';
        }
      }
      ,send_to: function(value){
        if(value.length < 1){
          return '验证码不能为空';
        }
      }
    });

      //交互
    form.on('submit(*)', function(data){
      //console.log(arr);
        $.ajax({
            url: "{:U('mobile/index/zhao_laoshi_add')}",//请求地址
            type: "post",//请求方式
            dataType: "json",//返回数据类型
            data: data.field,//发送的参数
            })
            .done(function(response) {
                  if(response.error==0){
                     layer.msg(response.info ,{icon:5});

                  }else{
                     layer.msg(response.info ,{icon:6});
                     location.reload();
                  }
              })
            .fail(function() {
                alert("ajxs交互失败");
            })  

          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });   
    });

    /*发送短信验证码*/
    function get_mobile_valid(){
        layer.confirm('确认要发送吗？',function(index){
            //发异步删除数据
            var to = $('input[name="phone"]').val();
            $.ajax({
                url: "{:U('mobile/user/send_to')}",//请求地址
                type: "post",//请求方式
                dataType: "json",//返回数据类型
                data: {to:to},//发送的参数
                })
                .done(function(response) {
                      if(response.error==1){
                        layer.msg(response.info ,{icon:6});
                      }else{
                        layer.msg(response.info ,{icon:5});
                      }
                  })
                .fail(function() {
                    alert("ajxs交互失败");
                })  
            return false;
        });
    }
</script>
</body>
</html>

